package com.di.base.controller;

import com.di.base.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

@Slf4j
@RestController
@RequestMapping("/account")
public class AccountController {

    @Resource
    private AccountService accountService;

    @GetMapping("/debit")
    public ResponseEntity<String> debitAccount(@RequestParam String userId, @RequestParam BigDecimal amount) {
        try {
            accountService.debit(userId, amount);
            return ResponseEntity.ok("扣款成功");
        } catch (Exception e) {
            log.error("扣款失败", e);
            throw new RuntimeException(e.getMessage());
        }
    }
}
